;; TODO: Move these into :test metadata of fns in math.clj

(in-namespace 'miked.math)

(refer '(miked.math))
(refer '(miked.unit-test assert-true assert-false assert-eql))

(assert-true "Divides true" '(divides 10 2))
(assert-false "Divides false" '(divides 10 3))
(assert-true "Even true" '(even 4))
(assert-false "Even false" '(even 5))
(assert-true "No divisor of 15" '(some-divisor? 15 (list 2 7 3)))
(assert-false "Divisor of 15" '(no-divisor? 15 (list 2 7 11 13)))

(assert-eql "Fib" (take 5 (list 1 2 3 5 8 13)) '(take 5 fib))

(assert-eql "Consolidate factors" '((1 3) (2 2) (3 1) (4 3))
	    '(consolidate-factors (list 1 1 1 2 2 3 4 4 4)))

(assert-eql "Factor" '((2 3) (3 1) (5 1))
	       '(factor 120))

(map (fn [x] (assert-true (strcat x " is prime") (prime? x)))
     '(2 3 5 7 11))

(map (fn [x] (assert-true (strcat x " is composite") (composite? x)))
       '(4 6 8 9 12))

(assert-eql "Odd sequence" (take 4 (list 3 5 7 9)) '(take 4 (odd-seq 3)))

(assert-false "1000 is composite" '(prime? 1000))

(assert-true "Palindrome" '(palindrome? (digits 12321)))
(assert-false "Not palindrome" '(palindrome? (digits 12345)))

(assert-eql "pow" 8 (pow 2 3))

(assert-eql '(1 2 3) '(digits 123))